<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增派遣任务')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<style>
    .jltable{
        margin: auto;
    }
    .jltable th,td{
        min-height: 40px;
        min-width: 50px;
        border: 1px solid #eee;
        padding: 10px;
    }
</style>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <h4 class="form-header h4">派遣任务</h4>
    <form class="form-horizontal m" id="form-pqrw-add">
        <table class="jltable">
            <tbody>
                    <tr>
                        <td><label class="control-label">类型：</label></td>
                        <td>
                            <select name="lx" class="form-control" th:with="type=${@dict.getType('pqrwlx')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </td>
                        <td></td><td></td>
                    </tr>
                    <tr>
                        <td><label class="control-label">标题：</label></td>
                        <td colspan="3"><input name="bt" class="form-control" type="text"></td>
                    </tr>

                    <tr>
                        <td><label class="control-label">所属项目：</label></td>
                        <td><input name="ssxm" class="form-control" type="text"></td>
                        <td></td><td></td>
                    </tr>
                    <tr>
                        <td><label class="control-label">分配给：</label></td>
                        <td colspan="3">
                            <input name="fpg" class="form-control" type="hidden">
                            <select  class="form-control" id="name_select" ></select>
                        </td>
                    </tr>

                    <tr>
                        <td><label class="control-label">说明：</label></td>
                        <td colspan="3"><textarea name="sm" class="form-control"></textarea></td>
                    </tr>
                    <tr>
                        <td><label class="control-label">开始时间：</label></td>
                        <td>
                            <div class="input-group date">
                                <input name="kssj" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </td>
                        <td><label class="control-label">截至时间：</label></td>
                        <td>
                            <div class="input-group date">
                                <input name="jzsj" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </td>
                    </tr>


                    <tr>
                        <td><label class="control-label">创建人：</label></td>
                        <td><input name="cjr" class="form-control" type="text"></td>
                        <td><label class="control-label">创建时间：</label></td>
                        <td>
                            <div class="input-group date">
                                <input name="cjsj" class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td><label class="control-label">相关文件：</label></td>
                        <td colspan="3">
                            <input type="hidden" name="xgwj">
                            <div class="file-loading">
                                <input class="form-control file-upload" id="xgwj" name="file" type="file">
                            </div>
                        </td>
                    </tr>
            </tbody>
        </table>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var prefix = ctx + "lwpq/pqrw"
    $("#form-pqrw-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-pqrw-add').serialize());
        }
    }

            $("input[name='kssj']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });

            $("input[name='jzsj']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });

            $("input[name='cjsj']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });

            $(".file-upload").fileinput({
                uploadUrl: ctx + 'common/upload',
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })


    $(function (){
        function formatRepo(repo){
            return  repo.name || repo.text;
        }
        function formatRepoSelection(repo){
            return  repo.name || repo.text;
        }

        $('#name_select').select2({
            multiple:true,
            ajax:{
                url: ctx + 'lwpq/jl/list',
                type:'post',
                dataType:'json',
                data:function (params) {
                    let query = {
                        name:params.term,
                        zt:'',
                    }
                    return query;
                },
                processResults : function (data){
                    let res = new Array();
                    data.rows.forEach(value => {
                        res.push({
                            id : value.id,
                            text : value.name,
                            ob:value
                        })
                    })
                    return {
                        results : res
                    };
                },
                minimumInputLength : 1,
                maximumInputLength : 20,
                templateResult : formatRepo,
                templateSelection : formatRepoSelection,
            }
        })
        $('#name_select').on('select2:select', function (e) {
            // 处理业务
            let ob =  e.params.data.ob;
            $("input[name='fpg']").val( $("input[name='fpg']").val() +","+ob.name);
        });
    })
</script>
</body>
</html>